package pzl.com.threadrelated.tasks;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-14]
 */
public class SubThread1 extends Thread {
    TextView tvShow;

    public SubThread1(TextView tv) {
        tvShow = tv;
    }

    @Override
    public void run() {
        Log.e("pzl", "子线程：" + Thread.currentThread().getName() + " run() start");
        Looper looper = Looper.getMainLooper();
        MyHandler1 handler = new MyHandler1(looper);
        Message message = handler.obtainMessage();
        message.obj = "sa bi ya 1";
        handler.sendMessage(message);
        Log.e("pzl", "子线程：" + Thread.currentThread().getName() + " run() end");
    }

    class MyHandler1 extends Handler {

        public MyHandler1(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Log.e("pzl", "handleMessage start 当前线程：" + Thread.currentThread().getName());
            tvShow.setText((CharSequence) msg.obj);
            Log.e("pzl", "handleMessage end 当前线程：" + Thread.currentThread().getName());
        }
    }

}
